package com.googlecode.dgwt.rebind.feature;

import com.google.gwt.core.ext.typeinfo.JMethod;
import com.googlecode.dgwt.client.dojo.Feature.MainClass;
import com.googlecode.dgwt.client.dojo.Feature.SuperClass;


/**
 * @author      Wellington Tadeu dos Santos
 * @since       DGWT v0.01
 */
public class FieldInjection {

    public JMethod method;
    
    public ClassInfo injectedClass;

    public SuperClass annotationSuperClass;
    
    public MainClass annotationMainClass;
    
    
    public void addAnnotation(SuperClass annotation) throws Exception {
        if (this.annotationSuperClass != null 
                && this.annotationSuperClass != annotation) {
            if (annotation == null) {
                return;
            }
            throw new Exception("Can not inject @SuperClass twice. Method: \"" + 
                    method.getEnclosingType().getQualifiedSourceName() + "." + method.getName() + "\"");
        }
        this.annotationSuperClass = annotation;
    }

    public void addAnnotation(MainClass annotation) throws Exception {
        if (this.annotationMainClass != null 
                && this.annotationMainClass != annotation) {
            if (annotation == null) {
                return;
            }
            throw new Exception("Can not inject @SuperClass twice. Method: \"" + 
                    method.getEnclosingType().getQualifiedSourceName() + "." + method.getName() + "\"");
        }
        this.annotationMainClass = annotation;
    }

}
